home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr44 / newmat08.zip / TMT2.CPP < prev    next >
C/C++ Source or Header  |  1995-01-11  |  3KB  |  91 lines

  1.  
  2. //#define WANT_STREAM
  3.  
  4.  
  5. #include "include.h"
  6.  
  7. #include "newmat.h"
  8.  
  9. /**************************** test program ******************************/
  10.  
  11. void Print(const Matrix& X);
  12. void Print(const UpperTriangularMatrix& X);
  13. void Print(const DiagonalMatrix& X);
  14. void Print(const SymmetricMatrix& X);
  15. void Print(const LowerTriangularMatrix& X);
  16.  
  17.  
  18. void trymat2()
  19. {
  20. //   cout << "\nSecond test of Matrix package\n\n";
  21.    Tracer et("Second test of Matrix package");
  22.    Exception::PrintTrace(TRUE);
  23.  
  24.    int i,j;
  25.    Matrix M(3,5);
  26.    for (i=1; i<=3; i++) for (j=1; j<=5; j++) M(i,j) = 100*i + j;
  27.    Matrix X(8,10);
  28.    for (i=1; i<=8; i++) for (j=1; j<=10; j++) X(i,j) = 1000*i + 10*j;
  29.    Matrix Y = X; Matrix Z = X;
  30.    { X.SubMatrix(2,4,3,7) << M; }
  31.    for (i=1; i<=3; i++) for (j=1; j<=5; j++) Y(i+1,j+2) = 100*i + j;
  32.    Print(Matrix(X-Y));
  33.  
  34.  
  35.    Real a[15]; Real* r = a;
  36.    for (i=1; i<=3; i++) for (j=1; j<=5; j++) *r++ = 100*i + j;
  37.    { Z.SubMatrix(2,4,3,7) << a; }
  38.    Print(Matrix(Z-Y));
  39.  
  40.    { M=33; X.SubMatrix(2,4,3,7) << M; }
  41.    { Z.SubMatrix(2,4,3,7) = 33; }
  42.    Print(Matrix(Z-X));
  43.  
  44.    for (i=1; i<=8; i++) for (j=1; j<=10; j++) X(i,j) = 1000*i + 10*j;
  45.    Y = X;
  46.    UpperTriangularMatrix U(5);
  47.    for (i=1; i<=5; i++) for (j=i; j<=5; j++) U(i,j) = 100*i + j;
  48.    { X.SubMatrix(3,7,5,9) << U; }
  49.    for (i=1; i<=5; i++) for (j=i; j<=5; j++) Y(i+2,j+4) = 100*i + j;
  50.    for (i=1; i<=5; i++) for (j=1; j<i; j++) Y(i+2,j+4) = 0.0;
  51.    Print(Matrix(X-Y));
  52.    for (i=1; i<=8; i++) for (j=1; j<=10; j++) X(i,j) = 1000*i + 10*j;
  53.    Y = X;
  54.    for (i=1; i<=5; i++) for (j=i; j<=5; j++) U(i,j) = 100*i + j;
  55.    { X.SubMatrix(3,7,5,9).Inject(U); }
  56.    for (i=1; i<=5; i++) for (j=i; j<=5; j++) Y(i+2,j+4) = 100*i + j;
  57.    Print(Matrix(X-Y));
  58.  
  59.  
  60.    // test growing and shrinking a vector
  61.    ColumnVector V(100);
  62.    for (i=1;i<=100;i++) V(i) = i*i+i;
  63.    V = V.Rows(1,50);               // to get first 50 vlaues.
  64.  
  65.    {
  66.       V.Release(); ColumnVector VX=V;
  67.       V.ReDimension(100); V = 0.0; V.Rows(1,50)=VX;
  68.    }                               // V now length 100
  69.  
  70. #if __ZTC__
  71.    ColumnVector VM = V; VM = 100;
  72. #else
  73.    M=V; M=100;                     // to make sure V will hold its values
  74. #endif
  75.    for (i=1;i<=50;i++) V(i) -= i*i+i;
  76.    Print(V);
  77.  
  78.     // test redimensioning vectors with two dimensions given
  79.    ColumnVector CV1(10); CV1 = 10;
  80.    ColumnVector CV2(5); CV2.ReDimension(10,1); CV2 = 10;
  81.    V = CV1-CV2; Print(V);
  82.  
  83.    RowVector RV1(20); RV1 = 100;
  84.    RowVector RV2; RV2.ReDimension(1,20); RV2 = 100;
  85.    V = (RV1-RV2).t(); Print(V);
  86.  
  87.  
  88.  
  89. //   cout << "\nEnd of second test\n";
  90. }
  91.